//
//  writePInfoViewController.m
//  marrymarry
//
//  Created by lsj on 16/9/8.
//  Copyright © 2016年 cf. All rights reserved.
//
static NSString * WriteInfoCellID = @"WriteInfoTableViewCell";
#import "writePInfoViewController.h"
#import "WriteInfoTableViewCell.h"
#import "HeadImgViewController.h"
#import "registerPayViewController.h"
#import "ChooseImgView.h"
#import "CFinfoModel.h"
@interface writePInfoViewController ()<UITableViewDataSource,UITableViewDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate,UITextFieldDelegate,UIPickerViewDataSource,UIPickerViewDelegate>
{
    BOOL _isRightImg;
    BOOL _isdeleteRight;
    BOOL _isSelectFinish;
    BOOL _isHaveHeadImg;
    BOOL _ispickLoad;
    NSString * _right_Img_homeStr;
    NSString * _left_Img_homeStr;
    NSString * _head_img_homeStr;
    NSString * _main_img_homeStr;
    NSString * _niChenStr;
    NSString * _sexStr;
    NSMutableDictionary * _myInfoDic;
    NSMutableDictionary * _myNetDic;
    NSMutableArray * _myPicArry;
    UIImage * _headImg;
    UIImage * _faceImg;
    UIImage * cacardImg;
    UIImage * cardPImg;
    
    NSDictionary * headImgDic;
    NSDictionary * faceImgDic;
    NSDictionary * cardImgDic;

}
@property (nonatomic,strong)CFinfoModel * model ;
@property (nonatomic,strong) UILabel * titleLable;
@property (nonatomic,strong)  UIButton * finishBtn;
@property (nonatomic, strong) NSArray *stringsArray;
@property (nonatomic, strong) NSArray *objectsArray;
@property (nonatomic, strong) NSArray *numbersArray;
@property (nonatomic, assign) id selectedObject;
@property (nonatomic, strong) NSString * selectedString;
@property (weak, nonatomic) IBOutlet UITableView *mytableView;
@property (weak, nonatomic) IBOutlet UIView *grayView;
@property (weak, nonatomic) IBOutlet UIPickerView *sexPickView;
@property (weak, nonatomic) IBOutlet UIButton *sureSexBtn;
@property (weak, nonatomic) IBOutlet UILabel *whiteLabel;
@property (strong, nonatomic) ChooseImgView * Chooseview;

@end

@implementation writePInfoViewController
-(CFinfoModel*)model
{
    if (!_model) {
        _model = [CFinfoModel new];
        
    }
    return _model;
}
-(ChooseImgView*)Chooseview
{
    if (!_Chooseview) {
        NSArray  *apparray= [[NSBundle mainBundle]loadNibNamed:@"ChooseImgView" owner:nil options:nil];
        //注意这里的类型名!
        //UIView *appview=[apparray firstObject];
        self.Chooseview=[apparray firstObject];
        self.Chooseview.frame=CGRectMake(0,0,ScreenWidth,400);
        self.Chooseview.backgroundColor = RGB(240, 239, 244);
    }
    return _Chooseview;
}

-(NSArray*)stringsArray
{
    if (!_stringsArray) {
        self.stringsArray = @[@"男",@"女"];
    }
    return _stringsArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _myInfoDic = [NSMutableDictionary new];
    _myNetDic = [NSMutableDictionary new];
    _myPicArry = [NSMutableArray new];
    // Do any additional setup after loading the view.
     self.view.backgroundColor = RGB(245, 245, 247);
    self.mytableView.backgroundColor = RGB(240, 239, 244);
    [self initNav];
    [self setTableViewFoot];
    _stringsArray = @[@"男", @"女"];
    _selectedString = [_stringsArray objectAtIndex:0];
    UITapGestureRecognizer * graytap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sureSexBtnDIdSelected:)];
    [self.grayView addGestureRecognizer:graytap];
    
    _myNetDic = [self.model readTheNetUserDic];
    
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    _isSelectFinish =NO;
    _isHaveHeadImg = YES;
    NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString * documentsDirectory = [paths objectAtIndex:0];
    NSLog(@" 2----- documentsDirectory ==== %@",documentsDirectory);
    NSString * homePath =[documentsDirectory stringByAppendingPathComponent:@"headIMG2.jpg"];
    NSString * mainPath =[documentsDirectory stringByAppendingPathComponent:@"mainIMG2.jpg"];
        _main_img_homeStr =homePath;
        _head_img_homeStr =mainPath;
        [self.mytableView reloadData];
   

}
#pragma mark ------- 设置导航栏
-(void)initNav
{
    self.navigationController.navigationBarHidden = YES;
    self.navigationController.navigationBar.hidden = YES;
    
    self.titleLable = [UILabel new];
    self.titleLable.frame = CGRectMake( 0, 20,ScreenWidth,44);
    self.titleLable.backgroundColor = RGB(245, 245, 247);
    self.titleLable.text = @"填写信息";
    self.titleLable.font = [UIFont systemFontOfSize:18];
    self.titleLable.textColor = [UIColor blackColor];
    self.titleLable.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:self.titleLable];
    self.finishBtn = [UIButton new];
    self.finishBtn.frame = CGRectMake(ScreenWidth-60,22,40,40);
    [self.finishBtn setTitleColor:RGB(0, 230, 196) forState:UIControlStateNormal];
    [self.finishBtn setTitle:@"完成" forState:UIControlStateNormal];
    [self.finishBtn addTarget:self action:@selector(goPayVC) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:self.finishBtn];
}
#pragma mark ------- 判断是否添加了认证图片
//判断文件是否已经在沙盒中已经存在？
-(BOOL) isFileExist:(NSString *)fileName
{
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString * documentsDirectory = [paths objectAtIndex:0];
    NSLog(@" 2----- documentsDirectory ==== %@",documentsDirectory);
    NSString * homePath =[documentsDirectory stringByAppendingPathComponent:fileName];
    NSString *uniquePath= homePath;
    
    BOOL result = [fileManager fileExistsAtPath:uniquePath];
    
    if(result)
    {
        NSLog(@"存在");
        if ([fileName rangeOfString:@"right2"].location!= NSNotFound ) {
            [Tools syncNSUserDeafaultsByKey:CARD_PIC withValue:_right_Img_homeStr];
        }else if ([fileName rangeOfString:@"left2"].location!= NSNotFound)
        {
            [Tools syncNSUserDeafaultsByKey:CARD_WITH_PEOPLE_PIC withValue:_left_Img_homeStr];
        }
    }
    else
    {
        if (_isSelectFinish) {
            [SVProgressHUD showErrorWithStatus:@"请上传认证照片"];
        }
        
    }
    return result;
}
#pragma mark -------删除沙盒下对应的文件
-(void)deleteFile:(NSString *)fileName {
    NSFileManager* fileManager=[NSFileManager defaultManager];
    //文件名
    BOOL result = [fileManager fileExistsAtPath:fileName];
    
    if (!result) {
        NSLog(@"no  have");
        return ;
    }else {
        NSLog(@" have");
        BOOL blDele= [fileManager removeItemAtPath:fileName error:nil];
        if (blDele) {
            NSLog(@"dele success");
            if (_isdeleteRight) {
                self.Chooseview.right_deleteBtn.hidden = YES;
                self.Chooseview.right_ImgView.image = [UIImage imageNamed:@"tianjia.jpg"];
            }else
            {
                self.Chooseview.left_deleteBtn.hidden = YES;
                self.Chooseview.left_ImgView.image = [UIImage imageNamed:@"tianjia.jpg"];
            }
            
        }else {
            NSLog(@"dele fail");
        }
        
    }
}


#pragma mark ------检查是否输入昵称
-(BOOL)checkName
{
    BOOL result;
    if ([_niChenStr isEqualToString:@""]||_niChenStr == nil) {
        [SVProgressHUD showErrorWithStatus:@"请输入昵称"];
        result = NO;
    }else{
        NSMutableDictionary * newdic =[NSMutableDictionary new];
         NSMutableDictionary * dic = [Tools getValueFromNSUserDefaultsByKey:MY_INFO_DIC];
       
        if (dic!= nil) {
             newdic = [NSMutableDictionary dictionaryWithDictionary:dic];
            NSDictionary * finialDic = [NSDictionary new];
            [newdic setObject:_niChenStr forKey:NICHEN_KEY];
            finialDic = [NSDictionary dictionaryWithDictionary:newdic];
            [Tools syncNSUserDeafaultsByKey:MY_INFO_DIC withValue:(NSDictionary*)finialDic];
        }else{
            NSDictionary * finialDic = [NSDictionary new];
            [newdic setObject:_niChenStr forKey:NICHEN_KEY];
            finialDic = [NSDictionary dictionaryWithDictionary:newdic];
            [Tools syncNSUserDeafaultsByKey:MY_INFO_DIC withValue:(NSDictionary *)finialDic];
        }
//        [_myInfoDic setObject:NICHEN_KEY forKey:_niChenStr];
//
//        [Tools syncNSUserDeafaultsByKey:@"niChen" withValue:_niChenStr];

     result = YES;
    }
    
    return result;
}



#pragma mark-------- 设置tableviewFootView
-(void)setTableViewFoot
{
   
    //加载视图
    self.mytableView.tableFooterView = self.Chooseview;
    self.Chooseview.left_deleteBtn.hidden = YES;
    self.Chooseview.right_deleteBtn.hidden = YES;
    self.Chooseview.left_ImgView.userInteractionEnabled = YES;
    self.Chooseview.right_ImgView.userInteractionEnabled = YES;
    UITapGestureRecognizer * imgTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goSetLeftImg)];
    [self.Chooseview.left_ImgView addGestureRecognizer:imgTap];
    UITapGestureRecognizer * right_imgTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goSetRightImg)];
    [self.Chooseview.right_ImgView addGestureRecognizer:right_imgTap];
    
    [self.Chooseview.right_deleteBtn addTarget:self action:@selector(deleteRightImg) forControlEvents:UIControlEventTouchUpInside];
    [self.Chooseview.left_deleteBtn addTarget:self action:@selector(deleteLeftImg) forControlEvents:UIControlEventTouchUpInside];
    
    
    
}

#pragma mark ------------ 删除右边的图片
-(void)deleteRightImg
{
    _isdeleteRight = YES;
    NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString * documentsDirectory = [paths objectAtIndex:0];
    NSLog(@" 2----- documentsDirectory ==== %@",documentsDirectory);
    NSString * rightPath =[documentsDirectory stringByAppendingPathComponent:_right_Img_homeStr];
   
    [self deleteFile:rightPath];
}
#pragma mark ------------ 删除左边的图片
-(void)deleteLeftImg
{
    _isdeleteRight = NO;
    
    NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString * documentsDirectory = [paths objectAtIndex:0];
    NSLog(@" 2----- documentsDirectory ==== %@",documentsDirectory);
    NSString * leftPath =[documentsDirectory stringByAppendingPathComponent:_left_Img_homeStr];
    
    [self deleteFile:leftPath];
}

-(void)goSetRightImg
{
    _isRightImg = YES;
    [self goSetImg];
}
-(void)goSetLeftImg
{
    _isRightImg = NO;
    [self gosetleftImg];
    
//    [self goSetImg];
}
-(void)goSetImg
{
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle: nil                                                                             message: nil                                                                       preferredStyle:UIAlertControllerStyleActionSheet];
    //添加Button
    [alertController addAction: [UIAlertAction actionWithTitle: @"拍照" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        //处理点击拍照
        [self gochoseImgWithCarmeraOrLibrary:YES];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle: @"从相册选取" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action){
        //处理点击从相册选取
        [self gochoseImgWithCarmeraOrLibrary:NO];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
    
    [self presentViewController: alertController animated: YES completion: nil];
}

-(void)gosetleftImg
{
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle: nil                                                                             message: nil                                                                       preferredStyle:UIAlertControllerStyleActionSheet];
    //添加Button
    [alertController addAction: [UIAlertAction actionWithTitle: @"拍照" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        //处理点击拍照
        [self gochoseImgWithCarmeraOrLibrary:YES];
    }]];
    [alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
    
    [self presentViewController: alertController animated: YES completion: nil];
}

-(void)gochoseImgWithCarmeraOrLibrary:(BOOL)isCarmra
{
    //读取图片的控制器
    UIImagePickerController *pick = [[UIImagePickerController alloc]init];
    
    //设置代理
    pick.delegate = self;
    
    //相片来源
    //UIImagePickerControllerSourceTypePhotoLibrary, 所有图片
    //UIImagePickerControllerSourceTypeCamera,       摄像头(模拟器会崩溃)
    //UIImagePickerControllerSourceTypeSavedPhotosAlbum 相册
    
    //判断当前设备是模拟器还是真机
    //模拟器
    if (isCarmra)
    {
        pick.sourceType = UIImagePickerControllerSourceTypeCamera;
    }else
    {
         pick.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        
    }
    
    //是否允许对选择的图片进行编辑
    pick.allowsEditing = YES;
    
    //推出图片选择器
    [self presentViewController:pick animated:YES completion:nil];
}

#pragma mark - UIImagePickerControllerDelegate
//选择图片的回调
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSLog(@"info==%@",info);
    if (_isRightImg)
    {
        self.Chooseview.right_deleteBtn.hidden = NO;
        //取到完整图片显示
        self.Chooseview.right_ImgView.image = info[@"UIImagePickerControllerEditedImage"];
        
        //让图片不失真,但是会超出边界
        self.Chooseview.right_ImgView.contentMode = UIViewContentModeScaleAspectFit;
        
        //UIImagePNGRepresentation     将image转成PNG格式二进制数据
        //UIImageJPEGRepresentation    将image转成JPG格式二进制数据
        //将UIImage转NSdata
        
        //第一个参数   需要转化的image对象
        //第二个参数   压缩比例
        NSData *data1 = UIImageJPEGRepresentation(info[@"UIImagePickerControllerEditedImage"], 0.00001);
        
        NSData *data2 = UIImageJPEGRepresentation(info[@"UIImagePickerControllerEditedImage"], 1.0);
        
        //取到沙盒路径
        NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString * documentsDirectory = [paths objectAtIndex:0];
        NSLog(@" 1----- documentsDirectory ==== %@",documentsDirectory);
        //    [data1 writeToFile:[homePath stringByAppendingString:@"/Documents/left1.jpg"] atomically:YES];
        NSString * savePicStr = [NSString stringWithFormat:@"right2.jpg"];
        [data2 writeToFile:[documentsDirectory stringByAppendingPathComponent:savePicStr] atomically:YES];
        cacardImg = [UIImage imageWithData:data2];
        
//        [data2 writeToFile:[homePath stringByAppendingString:@"/Documents/right2.jpg"] atomically:YES];
        _right_Img_homeStr = savePicStr;
        
    }
    else
    {
        self.Chooseview.left_deleteBtn.hidden = NO;
    //取到完整图片显示
    self.Chooseview.left_ImgView.image = info[@"UIImagePickerControllerEditedImage"];
    
    //让图片不失真,但是会超出边界
    self.Chooseview.left_ImgView.contentMode = UIViewContentModeScaleAspectFit;
    
    //UIImagePNGRepresentation     将image转成PNG格式二进制数据
    //UIImageJPEGRepresentation    将image转成JPG格式二进制数据
    //将UIImage转NSdata
    
    //第一个参数   需要转化的image对象
    //第二个参数   压缩比例
    NSData *data1 = UIImageJPEGRepresentation(info[@"UIImagePickerControllerEditedImage"], 0.00001);
    
    NSData *data2 = UIImageJPEGRepresentation(info[@"UIImagePickerControllerEditedImage"], 1.0);
    
    //取到沙盒路径
        NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString * documentsDirectory = [paths objectAtIndex:0];
        NSLog(@" 1----- documentsDirectory ==== %@",documentsDirectory);
        //    [data1 writeToFile:[homePath stringByAppendingString:@"/Documents/left1.jpg"] atomically:YES];
        NSString * savePicStr = [NSString stringWithFormat:@"left2.jpg"];
        [data2 writeToFile:[documentsDirectory stringByAppendingPathComponent:savePicStr] atomically:NO];
        
        cardPImg = [UIImage imageWithData:data2];
       
    _left_Img_homeStr = savePicStr;
    //将NSData转UIImage
    //    UIImage *image = [[UIImage alloc]initWithData:data1];
    }
    
#if 0
    //NSString 和 NSData 互转
    NSString *string = [[NSString alloc]initWithData:data1 encoding:NSUTF8StringEncoding];
    
    NSData *data = [@"hello" dataUsingEncoding:NSUTF8StringEncoding];
#endif
    
    
    //退出图片选择器
    [picker dismissViewControllerAnimated:YES completion:nil];
}



#pragma mark -----UITableViewDataSource,UITableViewDelegate

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    WriteInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:WriteInfoCellID];
    if (!cell) {
        cell = [[WriteInfoTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:WriteInfoCellID];
        
    }
    [cell reloadTheViewsWithIndexPath:indexPath];
    cell.tag = 1006;
    cell.UsrNameT.delegate =self;
    if (_isHaveHeadImg == YES && indexPath.section ==1) {
        NSData * headData = [NSData dataWithContentsOfFile:_head_img_homeStr];
        _headImg = [UIImage imageWithData:headData];
        [cell.headImgView setImage:[UIImage imageWithData:headData]];
        NSData *mainData = [NSData dataWithContentsOfFile:_main_img_homeStr];
        _faceImg = [UIImage imageWithData:mainData];
        [cell.mainImgView setImage:_faceImg];
        

    }
    if (_sexStr&&indexPath.section ==2) {
        cell.sexLabel.text = _sexStr;
    }
    return cell;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1) {
        return 100;
    }else{
        return 50;
    }

}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        NSLog(@"姓名");
        
    }else if (indexPath.section == 1)
    {
        NSLog(@"点击了设置头像");
        HeadImgViewController *headImgVC = [[UIStoryboard storyboardWithName:@"HeadImgViewController" bundle:nil] instantiateViewControllerWithIdentifier:@"HeadImgViewController"];
        headImgVC.isFromWrite = YES;
        [self.navigationController pushViewController:headImgVC animated:YES];

        
    }else if (indexPath.section == 2)
    {
        NSLog(@"点击了设置性别");
        _sexStr = @"男";
        _ispickLoad = YES;
        self.mytableView.userInteractionEnabled = NO;
        self.grayView.hidden = NO;
        self.grayView.alpha = 0.5;
        self.sexPickView.hidden =NO;
        self.sureSexBtn.hidden = NO;
        self.titleLable.hidden = YES;
        self.finishBtn.hidden=YES;
        self.whiteLabel.hidden = NO;
        [self.mytableView reloadData];
    }
    
}



-(void)textFieldDidEndEditing:(UITextField *)textField
{
    _niChenStr = textField.text;
}




#pragma mark --- 与DataSource有关的代理方法
//返回列数（必须实现）
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

//返回每列里边的行数（必须实现）
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    //如果是第一列
    if (component == 0) {
        //返回姓名数组的个数
        return self.stringsArray.count;
    }
    else
    {
        return 1;
        //返回表情数组的个数
//        return self.iconArray.count;
    }
    
}

#pragma mark --- 与处理有关的代理方法
//设置组件的宽度
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
    if (component == 0) {
        return ScreenWidth;
    }
    else
    {
        return 80;
    }
    
}
//设置组件中每行的高度
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    if (component == 0) {
        return 60;
    }
    else
    {
        return 60;
    }
}
//设置组件中每行的标题row:行
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (component == 0) {
        return self.stringsArray[row];
    }
    else
    {
        return self.stringsArray[row];
    }
}


//选中行的事件处理
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (component == 0) {
        NSLog(@"%@",self.stringsArray[row]);
        [pickerView selectedRowInComponent:0];
        //        //重新加载数据
//                [pickerView reloadAllComponents];
        //        //重新加载指定列的数据
//                [pickerView reloadComponent:0];
    }
    else
    {
        NSLog(@"%@",self.stringsArray[row]);
    }
    
    _sexStr = self.stringsArray[row];
    [self.mytableView reloadData];
    
}

- (IBAction)sureSexBtnDIdSelected:(UIButton *)sender {
    _ispickLoad = NO;
    self.sexPickView.hidden= YES;
    self.grayView.hidden= YES;
    self.sureSexBtn.hidden=YES;
    self.titleLable.hidden = NO;
    self.finishBtn.hidden=NO;
    self.mytableView.userInteractionEnabled =YES;
    self.whiteLabel.hidden = YES;
}

#pragma mark ------存储性别
-(BOOL)checkSex
{
    BOOL result;
    if ([_sexStr isEqualToString:@""]||_sexStr == nil) {
        [SVProgressHUD showErrorWithStatus:@"请输选择性别"];
        result = NO;
    }else{
        NSMutableDictionary * newdic =[NSMutableDictionary new];
        NSMutableDictionary * dic = [Tools getValueFromNSUserDefaultsByKey:MY_INFO_DIC];
        
        if (dic!= nil) {
            newdic = [NSMutableDictionary dictionaryWithDictionary:dic];
            NSDictionary * finialDic = [NSDictionary new];
            [newdic setObject:_sexStr forKey:SEX_KEY];
            finialDic = [NSDictionary dictionaryWithDictionary:newdic];
            [Tools syncNSUserDeafaultsByKey:MY_INFO_DIC withValue:(NSDictionary*)finialDic];
        }else{
            NSDictionary * finialDic = [NSDictionary new];
            [newdic setObject:_sexStr forKey:SEX_KEY];
            finialDic = [NSDictionary dictionaryWithDictionary:newdic];
            [Tools syncNSUserDeafaultsByKey:MY_INFO_DIC withValue:(NSDictionary *)finialDic];
        }
  
//        [Tools syncNSUserDeafaultsByKey:@"Mysex" withValue:_sexStr];
        result = YES;
    }
    
    return result;
}



#pragma mark ------ 去认证页面
-(void)goPayVC
{
    if (cardPImg == nil||cacardImg == nil || _headImg == nil || _faceImg == nil) {
        [SVProgressHUD showErrorWithStatus:@"请上传照片"];
        return;
    }
    
    NSArray * cardArry  =@[cardPImg,cacardImg];
    headImgDic = @{@"imgname":@"headimg",@"pic":_headImg};
    faceImgDic = @{@"imgname":@"faceimg",@"pic":_faceImg};
    cardImgDic = @{@"imgname":@"cacardimg",@"pic":cardArry};
    [_myPicArry addObject:headImgDic];
    [_myPicArry addObject:faceImgDic];
    [_myPicArry addObject:cardImgDic];
    _isSelectFinish = YES;
    NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString * documentsDirectory = [paths objectAtIndex:0];
    NSLog(@" 2----- documentsDirectory ==== %@",documentsDirectory);

    
    if ([self isFileExist:_right_Img_homeStr] && [self isFileExist:_left_Img_homeStr]&& [self checkName]&&[self checkSex])
    {
        NSLog(@"点击了完成");
       
        NSDictionary* dic = @{@"user_name":_niChenStr,@"id":_myNetDic[@"id"],@"sex":_sexStr};
        [[LJFNetworkingManager shareManager] POST:PUSH_SMAPLE_URL upLoadImages:_myPicArry parameters:dic success:^(id returnData, int code, NSString *msg) {
            
            registerPayViewController *registerVC = [[UIStoryboard storyboardWithName:@"registerPayViewController" bundle:nil] instantiateViewControllerWithIdentifier:@"registerPayViewController"];
            [self.navigationController pushViewController:registerVC animated:YES];
            
            
        } failure:^(NSError *error) {
            
        } showHUD:self.view];
        
        
       
        
    }
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
